<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <h2>采购信息查询</h2>
        </div>
      </el-col>
    </el-row>

    <el-row style="margin-top: 20px">
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-table
              :data="tableData"
              highlight-current-row
              @current-change="handleCurrentChange"
              style="width: 100%">
            <el-table-column
                prop="productBean.productName"
                label="商品名称"
                align="center">
            </el-table-column>
            <el-table-column
                prop="productBean.productFirm"
                label="厂家"
                align="center">
            </el-table-column>
            <el-table-column
                prop="productBean.productBuyer"
                label="建议采购价"
                align="center">
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <el-pagination
              background
              layout="prev, pager, next"
              :total="total"
              :page-size="pageSize"
              :current-page="currentPage"
              @current-change="currentPageFn">
          </el-pagination>
        </div>
      </el-col>

      <el-col :span="8">
        <div class="grid-content bg-purple" style="margin-top: 20px">
          <el-button type="primary" plain @click="addProduct">添加商品</el-button>
        </div>
      </el-col>

      <el-col :span="12">
        <div class="grid-content bg-purple-light" style="margin-left: 10px">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>查询采购信息</span>

              <el-row >
                <el-col :span="7" class="labClass">
                  <div class="grid-content bg-purple" style="margin-top: 30px">
                    商品名称：
                  </div>
                </el-col>
                <el-col :span="15">
                  <div class="grid-content bg-purple-light" style="margin-top: 20px">
                    <el-input v-model="productName" placeholder="请输入内容" class="labClass"></el-input>
                  </div>
                </el-col>
              </el-row>

              <el-row style="margin-top: 10px">
                <el-col :span="7" class="labClass">
                  <div class="grid-content bg-purple" style="margin-top: 25px">
                    类别：
                  </div>
                </el-col>
                <el-col :span="15">
                  <div class="grid-content bg-purple-light" style="margin-top: 20px">
                    <el-input v-model="productName" placeholder="请输入内容" class="labClass"></el-input>
                  </div>
                </el-col>
              </el-row>
            </div>
            <el-button type="primary" plain style="margin-right: 20px" @click="init">查询</el-button>
          </el-card>
        </div>
      </el-col>
    </el-row>



  </div>


</template>

<script>
export default {
  name: "addProduct",
  data() {
    return {
      tableData: [],
      total: 0,
      pageSize: 4,
      currentPage: 1,
      productName:'',
      productClass:'',
      currentRow:'',
      clientId:''
    }
  },
  mounted() {
    this.init();
  },
  methods: {
    newInit(id){
      this.clientId=id
    }
    ,
    init() {
      let params = {
        current: this.currentPage,
        size: this.pageSize,
        productName: this.productName,
        startDate: null,
        endDate:null,
        productClass:this.productClass
      }

      this.$axios.get('drp/stock/findBySupplierItem',{params:params}).then(
          r => {
            this.tableData = r.data.records;
            this.total=r.data.total
          }
      )
      let loginUser = sessionStorage.getItem("loginUser")
      if (sessionStorage.getItem("loginUser") != null) {
        this.userName = JSON.parse(loginUser).realName
        this.userId = JSON.parse(loginUser).userId
      }
    },
    handleCurrentChange(val) {
      this.currentRow = val
      console.log(val)
    },
    currentPageFn(currentPage) {
      this.currentPage = currentPage
      this.init()
    },
    addProduct(){
      if(this.currentRow==''){
        this.$message.warning("请选中一行")
      }else {
        let formData=new FormData()
        console.log('添加商品id   '+this.clientId)
        console.log('库存id   '+this.currentRow.stockId)
        formData.append("ClientId",this.clientId)
        formData.append("StockId",this.currentRow.stockId)
        formData.append("number",0)
        this.$axios.post("drp/orderdetail/addOrder",formData).then(
            r=>{
              if (r.data=='ok'){
                location.href="/index"
              }
            }
        )
      }
    }
  }
}
</script>

<style scoped>

</style>